﻿using System;
using System.Net;
using Terraria.GameContent.UI.Elements;
using Terraria.Localization;
using Terraria.UI;

namespace Terraria.ModLoader.UI
{
	// Token: 0x02000280 RID: 640
	internal class UIDownloadMod : UIState
	{
		// Token: 0x06001A25 RID: 6693 RVA: 0x00427F2C File Offset: 0x0042612C
		public override void OnInitialize()
		{
			this.loadProgress = new UILoadProgress();
			this.loadProgress.Width.Set(0f, 0.8f);
			this.loadProgress.MaxWidth.Set(600f, 0f);
			this.loadProgress.Height.Set(150f, 0f);
			this.loadProgress.HAlign = 0.5f;
			this.loadProgress.VAlign = 0.5f;
			this.loadProgress.Top.Set(10f, 0f);
			base.Append(this.loadProgress);
			UITextPanel<string> uitextPanel = new UITextPanel<string>(Language.GetTextValue("UI.Cancel"), 0.75f, true);
			uitextPanel.VAlign = 0.5f;
			uitextPanel.HAlign = 0.5f;
			uitextPanel.Top.Set(170f, 0f);
			uitextPanel.OnMouseOver += UICommon.FadedMouseOver;
			uitextPanel.OnMouseOut += UICommon.FadedMouseOut;
			uitextPanel.OnClick += this.CancelClick;
			base.Append(uitextPanel);
		}

		// Token: 0x06001A26 RID: 6694 RVA: 0x00012908 File Offset: 0x00010B08
		public override void OnActivate()
		{
			this.loadProgress.SetText(Language.GetTextValue("tModLoader.MBDownloadingMod", this.name));
			this.loadProgress.SetProgress(0f);
		}

		// Token: 0x06001A27 RID: 6695 RVA: 0x00012935 File Offset: 0x00010B35
		internal void SetDownloading(string name)
		{
			this.name = name;
		}

		// Token: 0x06001A28 RID: 6696 RVA: 0x0001293E File Offset: 0x00010B3E
		public void SetCancel(Action cancelAction)
		{
			this.cancelAction = cancelAction;
		}

		// Token: 0x06001A29 RID: 6697 RVA: 0x00012947 File Offset: 0x00010B47
		internal void SetProgress(DownloadProgressChangedEventArgs e)
		{
			this.SetProgress(e.BytesReceived, e.TotalBytesToReceive);
		}

		// Token: 0x06001A2A RID: 6698 RVA: 0x0001295B File Offset: 0x00010B5B
		internal void SetProgress(long count, long len)
		{
			UILoadProgress uiloadProgress = this.loadProgress;
			if (uiloadProgress == null)
			{
				return;
			}
			uiloadProgress.SetProgress((float)count / (float)len);
		}

		// Token: 0x06001A2B RID: 6699 RVA: 0x00012972 File Offset: 0x00010B72
		private void CancelClick(UIMouseEvent evt, UIElement listeningElement)
		{
			Main.PlaySound(10, -1, -1, 1, 1f, 0f);
			this.cancelAction();
		}

		// Token: 0x04001772 RID: 6002
		private UILoadProgress loadProgress;

		// Token: 0x04001773 RID: 6003
		private string name;

		// Token: 0x04001774 RID: 6004
		private Action cancelAction;
	}
}
